package com.surfacing.rcp.client.controller;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;

import com.surfacing.rcp.core.net.NetWrapper;
import com.surfacing.rcp.model.common.IProgramStatus;
import com.surfacing.rcp.model.common.ITransportStatus;
import com.surfacing.rcp.model.entity.Journal;

/**
 * Sets the given journal status
 * 
 * @author b.thek
 */
public class SetTransportStatusAction extends Action implements
		ITransportStatus, IProgramStatus {
	// properties
	private TableViewer viewer;

	/**
	 * Constructor to set the given journal status
	 * 
	 * @param viewer
	 *            the table viewer
	 * @param status
	 *            the journal status to set
	 */
	public SetTransportStatusAction(TableViewer viewer, int status,
			String shownAs) {
		this.viewer = viewer;
		setText(shownAs);
		setToolTipText("Setzt den Transportstatus " + " " + shownAs);
	}

	@Override
	public void run() {
		// the selection
		ISelection selection = viewer.getSelection();
		// get the selected journal
		Journal journal = (Journal) ((IStructuredSelection) selection)
				.getFirstElement();
		// create the time stamp
//		GregorianCalendar gcal = new GregorianCalendar();
//		long timestamp = gcal.getTimeInMillis();
		// set the status

		NetWrapper.getDefault().sendUpdateMessage(Journal.ID, journal);
	}
}
